package com.xxy.controller;

import com.xxy.entity.Order;
import com.xxy.entity.dto.OrderQueryDTO;
import com.xxy.entity.vo.OrderVO;
import com.xxy.result.PageResult;
import com.xxy.result.Result;
import com.xxy.service.IOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private IOrderService orderService;

    @PostMapping("/save")
    public Result<String> save(Order order) {
        orderService.save(order);
        return Result.success("保存成功");
    }

    @PutMapping("/update")
    public Result<String> update(Order order) {
        orderService.updateById(order);
        return Result.success("更新成功");
    }
    @DeleteMapping("/delete")
    public Result<String> delete(Integer id) {
        orderService.removeById(id);
        return Result.success("删除成功");
    }
    @DeleteMapping("/deleteBatch")
    public Result<String> deleteBatch(@RequestBody List<Integer> ids) {
        orderService.removeBatchByIds(ids);
        return Result.success("删除成功");
    }

    @PostMapping("/queryByFilter")
    public Result<List<OrderVO>> queryByFilter(OrderQueryDTO orderQueryDTO) {
        List<OrderVO> orderVOList = orderService.queryByFilter(orderQueryDTO);
        return Result.success(orderVOList);
    }
    @PostMapping("query")
    public Result<PageResult> query(@RequestBody OrderQueryDTO orderQueryDTO) {
        PageResult pageResult = orderService.query(orderQueryDTO);
        return Result.success(pageResult);
    }

}
